from selenium.webdriver.common.by import By
from pages.base_page import BasePage


class RzPage(BasePage):
    url = "http://192.168.1.55/crm/index.php?m=log"
    rz_page_success_locator = (By.XPATH,"/html/body/div[5]/div[2]/button")
    delete_page_success_locator = (By.XPATH, "/html/body/div[5]/div[2]/button")
    # 清楚数据定位表格
    tbody_locator = (By.CSS_SELECTOR, "#form1 > table > tbody")
    delate_locator = (By.ID, "delete")

    def delete_click(self,name):
        """清楚数据"""
        tbody = self.driver.find_element(*self.tbody_locator)
        trs = tbody.find_elements(By.TAG_NAME, "tr")
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[2].text == name:
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="log_id[]"]').click()
                break
        self.driver.find_element(*self.delate_locator).click()
        self.driver.switch_to.alert.accept()

    def get_rzps_text(self):
        return self.driver.find_element(*self.rz_page_success_locator).text
    def get_rz_delete_text(self):
        return self.driver.find_element(*self.delete_page_success_locator).text